package jse;

/**
 * @desc   重写hashcode方法
 * @author kanggw
 * @datetime 2016年3月24日,下午9:44:46
 */
public class WriteHashCode {
	
	private String name;
	private int age;
	private double weight;

	public WriteHashCode() {
		
	}
	
	public WriteHashCode(String name,int age,double weight) {
		
		this.name = name;
		this.age = age;
		this.weight = weight;
	}

	@Override
	public int hashCode() {
		 
		return 7*name.hashCode() + 11 * new Integer(age).hashCode() + 13 * new Double(weight).hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		 
		//如果是同一个对象则相同
		if(this == obj) {
			return true;
		}
		//如果有一个为空则不同
		if(obj == null) {
			return false;
		}
		//如果类型不同则不同
		if(getClass() != obj.getClass()) {
			return false;
		}
		
		WriteHashCode cat = new WriteHashCode();
		return name.equals(cat.name) &&  (age == cat.age) && (weight == cat.weight);
	}
	
	
	
	
	
}
